package com.power.using.mydaggerp.ui.activity.detial;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;

import com.bumptech.glide.Glide;
import com.power.using.mydaggerp.base.BasePresenter;
import com.power.using.mydaggerp.constant.BundleKeyConstant;
import com.power.using.mydaggerp.contract.detail.WangyiDetailContract;
import com.power.using.mydaggerp.model.bean.wangyi.WangyiNewsDetailBean;
import com.power.using.mydaggerp.presenter.detail.WangyiDetailPresenter;
import com.zyw.horrarndoo.sdk.utils.HtmlUtils;

/**
 * Created by 聪明一只哈 on 2019/10/11.
 * Time: 2019/10/11  14:55
 */
public class WangyiDailyDetailActivity extends BaseWebViewLoadActivity<WangyiDetailContract.WangyiDetailPresenter>
                implements WangyiDetailContract.IWangyiDetailView{

    private String mTitle, mUrl, mId, mImageUrl, mCopyright;

    @Override
    protected void initData() {
        super.initData();
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            mId = bundle.getString(BundleKeyConstant.ARG_KEY_WANGYI_DETAIL_ID);
            mUrl = bundle.getString(BundleKeyConstant.ARG_KEY_WANGYI_DETAIL_URL);
            mTitle = bundle.getString(BundleKeyConstant.ARG_KEY_WANGYI_DETAIL_TITLE);
            mImageUrl = bundle.getString(BundleKeyConstant.ARG_KEY_WANGYI_DETAIL_IMAGE_URL);
            mCopyright = bundle.getString(BundleKeyConstant.ARG_KEY_WANGYI_DETAIL_COPYRIGHT);
        }
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        tvDetailTitle.setText(mTitle);
        tvDetailCopyright.setText(mCopyright);
        Glide.with(mContext).load(mImageUrl).crossFade().into(ivDetail);

    }

    @NonNull
    @Override
    public BasePresenter initPresenter() {
        return WangyiDetailPresenter.newInstance();
    }

    @Override
    public void showNewsDetail(WangyiNewsDetailBean bean) {

        flNetView.setVisibility(View.GONE);
        nswvDetailContent.loadData(bean.getBody(), HtmlUtils.MIME_TYPE,HtmlUtils.ENCODING);

    }

    @Override
    public void showNewsDetail(String url) {
        flNetView.setVisibility(View.GONE);
        nswvDetailContent.loadUrl(url);
    }

    @Override
    protected void loadDetail() {
        mPresenter.loadNewsDetailWithUrl(mUrl);

    }

    @Override
    protected String getToolbarTitle() {
        return "热点新闻";//ResourcesUtils.getString(R.string.wangyi_detail_title)

    }
}
